package com.hxzy.shop.controller.member;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.dto.member.req.LabelListsReq;
import com.hxzy.shop.dto.member.req.MemberCardListsReq;
import com.hxzy.shop.dto.member.req.MemberDetailsReq;
import com.hxzy.shop.dto.member.req.MemberListsReq;
import com.hxzy.shop.dto.member.resp.LabelListsResp;
import com.hxzy.shop.dto.member.resp.MemberDetailResp;
import com.hxzy.shop.dto.member.resp.MemberLabelResp;
import com.hxzy.shop.dto.member.resp.MemberListsResp;
import com.hxzy.shop.feign.member.MemberFeign;
import com.hxzy.shop.vo.ApiException;
import com.hxzy.shop.vo.Result;
import com.hxzy.shop.vo.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author admin
 * @Desc
 * @Date 2023/8/4
 */
@RestController
@Api(tags = "会员-查看会员")
@RequestMapping("/member")
public class MemberController {

    @Resource
    private MemberFeign memberFeign;

    /**
     * 查看会员- 会员列表
     *
     * @param req 会员列表请求体
     * @return 查询的会员列表
     */
    @ApiOperation("会员列表")
    @PostMapping(value = "/memberLists")
    public Result<PageInfo<MemberListsResp>> memberLists(@RequestBody MemberListsReq req){
        Result<PageInfo<MemberListsResp>> pageInfoResult = memberFeign.memberLists(req);
        if (pageInfoResult.getCode() != ResultCode.SUCCESS.getCode()){
            throw new ApiException(500, pageInfoResult.getMsg());
        }
        return  Result.success(pageInfoResult.getData());
    }

    /**
     * 查看会员- 会员详细
     *
     * @param req 会员详细请求体
     * @return 会员详细信息
     */
    @ApiOperation(value = "会员详情")
    @PostMapping(value = "/memberDetails")
    public Result<MemberDetailResp> memberDetails(@RequestBody MemberDetailsReq req){
        Result<MemberDetailResp> resp = memberFeign.memberDetails(req);
        if(resp.getCode()!=ResultCode.SUCCESS.getCode()){
            throw new ApiException(500,resp.getMsg());
        }
        return Result.success(resp.getData());
    }

    /**
     * 获得会员卡列表
     *
     * @param req 会员请求体
     * @return 会员列表
     */
    @ApiOperation("会员卡列表")
    @PostMapping(value = "/memberCardLists")
    public Result<Map<String,Object>> memberCardLists(@RequestBody MemberCardListsReq req){
        Result<Map<String, Object>> mapResult = memberFeign.memberCardLists(req);
        if (mapResult.getCode()!=ResultCode.SUCCESS.getCode()){
            throw new ApiException(500,mapResult.getMsg());
        }
        return Result.success(mapResult.getData());
    }

    /**
     * 会员标签列表
     *
     * @param req 标签列表请求体
     * @return {@code PageInfo<LabelListsResp>}
     */
    @PostMapping("/labelLists")
    @ApiOperation(value = "会员标签列表")
    public Result<LabelListsResp> labelLists(@RequestBody @Validated LabelListsReq req){
        Result<LabelListsResp> respResult = memberFeign.labelLists(req);
        if (respResult.getCode()!=ResultCode.SUCCESS.getCode()){
            throw new ApiException(500,respResult.getMsg());
        }
        return Result.success(respResult.getData());
    }

    /**
     * 会员标签列表
     *
     * @param req memberDetailsReq
     * @return 会员标签
     */
    @ApiOperation(value = "会员标签列表")
    @PostMapping(value = "/getMemberLabel")
    public Result<List<MemberLabelResp>> getMemberLabel(@RequestBody MemberDetailsReq req) {
        return memberFeign.getMemberLabel(req);
    }
}
